package com.mohan.dlxj.controller;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.common.R;
import com.mohan.dlxj.pojo.Circuit;
import com.mohan.dlxj.service.CircuitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("circuit")
public class CircuitController {
  @Autowired
  private CircuitService circuitService;

  @GetMapping("pageCircuit")
  public JsonResult pageCircuit(long page,long limit){
    JsonResult jsonResult= circuitService.getCircuitList(page,limit);
    return jsonResult;
  }

  @GetMapping("getAllNum")
  public R getAllNum() {
    Integer all = circuitService.getCircuitAll();
    R r = new R();
    r.setData(all);
    r.setCode(200);
    r.setMsg("成功");
    return r;
  }

  @GetMapping("getCircuitById/{id}")
  public R getCircuitById(@PathVariable Integer id) {
    Circuit role = circuitService.getCircuitById(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("查询成功");
    r.setData(role);
    return r;
  }

  @PostMapping("updateCircuit")
  public R updateCircuit(Circuit circuit) {
    circuitService.updateCircuit(circuit);
    R r = new R();
    r.setCode(200);
    r.setMsg("更新电杆成功");
    return r;
  }

  @DeleteMapping("deleteCircuit/{id}")
  public R deleteCircuit(@PathVariable Integer id) {
    circuitService.deleteCircuit(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("删除电杆成功");
    return r;
  }


  @PostMapping("saveCircuit")
  public R saveCircuit(Circuit circuit) {
    circuitService.saveCircuit(circuit);
    R r = new R();
    r.setCode(200);
    r.setMsg("添加电杆成功");
    return r;
  }

  @PostMapping("updateStartusing/{id}")
  public R updateStartusing(@PathVariable long id) {
    circuitService.updateStartusing(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("更新状态成功");
    return r;
  }

}
